package com.vincent.template.controller.manage;

import com.vincent.template.commons.base.VctVo;
import com.vincent.template.dto.sys.usergroup.UserGroupDto;
import com.vincent.template.service.logic.UserGroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Vincent Wang
 * @date 2021/3/25 17:24
 */
@Api(tags = "用户组管理")
@RestController
@RequestMapping("/manage/userGroup")
public class UserGroupController {

    @Autowired
    private UserGroupService userGroupService;

    @ApiOperation("查询所有用户组")
    @GetMapping
    public List<UserGroupDto> findUserGroups() {
        return userGroupService.findUserGroups();
    }

    @ApiOperation("根据id查询用户组")
    @GetMapping("/{id}")
    public UserGroupDto findUserGroupById(@PathVariable("id") Long id) {
        return userGroupService.findUserGroupById(id);
    }

    @ApiOperation("添加用户组")
    @PostMapping("/create")
    public VctVo<Long> addUserGroup(@Validated @RequestBody UserGroupDto groupDto) {
        return VctVo.id(userGroupService.addUserGroup(groupDto));
    }

    @ApiOperation("更新用户组")
    @PutMapping("/{id}/update")
    public boolean updateUserGroup(@PathVariable("id") Long id,
                                   @Validated @RequestBody UserGroupDto groupDto) {
        return userGroupService.updateUserGroup(id, groupDto);
    }

    @ApiOperation("删除用户组")
    @DeleteMapping("/{id}/delete")
    public boolean deleteUserGroup(@PathVariable("id") Long id) {
        return userGroupService.deleteUserGroup(id);
    }
}
